package kku.cs.hero;

import org.newdawn.slick.Graphics;

import kku.cs.fgl.Actor;
import kku.cs.fgl.SpriteCell;
import kku.cs.fgl.SpriteSheet;

public class TileMapActor extends Actor {
    public int map[][];
    SpriteSheet sheet;
    int tw, th;
    SpriteCell bg;

    public TileMapActor(SpriteSheet sheet, int map[][]) {
        super(0, 0);
        this.sheet = sheet;
        this.map = map;
        bg = sheet.getCell(0);
        tw = bg.getWidth();
        th = bg.getHeight();
    }

    public void init(int tw, int th, int colcount, int rowcount) {
        map = new int[rowcount][colcount];
        this.tw = tw;
        this.th = th;
        for (int j = 0; j < rowcount; j++) {
            for (int k = 0; k < colcount; k++) {
                map[j][k] = -1;
            }
        }
    }

    @Override
    public void paint(Graphics g) {
        for (int i = 0; i < map.length; i++) {
            for (int j = 0; j < map[i].length; j++) {
                if (map[i][j] >= 0) {
                    SpriteCell cell = sheet.getCell(map[i][j]);
                    int x = j * tw;
                    int y = i * th;
                    bg.paint(g, x, y, null);
                    if (cell != null) {
                        cell.paint(g, x, y, null);
                    }
                }
            }
        }
    }
}
